﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ParserCore;

namespace TestParser
{
    [TestClass]
    public partial class ParserUnitTestTrle
    {
        [TestMethod]
        public void SwitchCaseTestMethod()
        {
            var expression = "switch x case 1 n = 1 otherwise n = 2 , end";
            var parser = new ParsingEngine();
            var statement = parser.Parse(expression);


            Statement switchstat = new SwitchCaseStatement(
                new Identifier("x"),
                new AssignmentStatement(
                    new Expression[] { new Identifier("n") }, 
                    new Constant("2", Constant.CType.RealNumber)),
                    new Tuple<Expression, Statement>[]{
                        new Tuple <Expression, Statement> ( 
                            new Constant("1", Constant.CType.RealNumber),
                            new AssignmentStatement(new Expression[] {new Identifier("n")} , new Constant("1", Constant.CType.RealNumber)))});

            Assert.AreEqual(switchstat, statement);

        }

        [TestMethod]
        public void WhileTestMethod()
        {
            var expression = "while x > 1 x = x - 1 ; end"; // ovo ne bi trebalo da prolazi
            var parser = new ParsingEngine();
            var statement = parser.Parse(expression);

            Statement whilestat = new WhileStatement(
                new Call(new Identifier(">"), new Identifier("x"), new Constant("1", Constant.CType.RealNumber)),
                new AssignmentStatement(
                    new Expression[] { new Identifier("x") },
                    new Call(new Identifier("-"), new Identifier("x"), new Constant("1", Constant.CType.RealNumber))));

            Assert.AreEqual(whilestat, statement);
        }

        [TestMethod]
        public void TryCatchTestMethod()
        {
            var expression = "try\n x = 13\n catch\n x = 0\n end";
            var parser = new ParsingEngine();
            var statement = parser.Parse(expression);

            Statement trycatch = new TryCatchStatement(
                new AssignmentStatement(new Expression[] { new Identifier("x") }, new Constant("13", Constant.CType.RealNumber)),
                new Identifier("_"),
                new AssignmentStatement(new Expression[] { new Identifier("x") }, new Constant("0", Constant.CType.RealNumber)));

            Assert.AreEqual(trycatch, statement);

            expression = "try\n x = 13\n catch y\n x = 0\n end";
            statement = parser.Parse(expression);
            trycatch = new TryCatchStatement(
                    new AssignmentStatement(new Expression[] { new Identifier("x") }, new Constant("13", Constant.CType.RealNumber)),
                    new Identifier("y"),
                    new AssignmentStatement(new Expression[] { new Identifier("x") }, new Constant("13", Constant.CType.RealNumber)));
        }

        [TestMethod]
        public void ForTestMethod()
        {
            var expression = "for k = A x = x + 1 \n end";
            var parser = new ParsingEngine();
            var statement = parser.Parse(expression);

            Statement forstat = new ForStatement(
                new Identifier("k"),
                new Identifier("A"),
                new AssignmentStatement(
                    new Expression[] { new Identifier("x") },
                    new Call(new Identifier("+"), new Identifier("x"), new Constant("1", Constant.CType.RealNumber))));

            Assert.AreEqual(forstat, statement);
        }

        [TestMethod]
        public void IfNullTestMethod()
        {
            var expression = "if x a b end";
            var parser = new ParsingEngine();
            var statement = parser.Parse(expression);

            Assert.AreEqual(statement, null); ;
        }
    }
}
